use ash::vk::{self, SemaphoreCreateFlags};

use crate::{vulkan::VkContext, VK_CHECK_UNSAFE, VK_LOGP};

impl VkContext {
    pub fn create_semaphore(&self) -> vk::Semaphore {
        let semaphore_ci = vk::SemaphoreCreateInfo {
            s_type      : vk::StructureType::SEMAPHORE_CREATE_INFO,
            p_next      : std::ptr::null(),
            flags       : SemaphoreCreateFlags::empty()
        };
        
        match VK_CHECK_UNSAFE!(self.vk_device.create_semaphore(&semaphore_ci, None)) {
            Some(inner_value)   => inner_value,
            None                => VK_LOGP!("Failed to create_semaphore")
        }
    }

    pub fn create_fence(&self) -> vk::Fence {
        let fence_ci = vk::FenceCreateInfo {
            s_type      : vk::StructureType::FENCE_CREATE_INFO,
            p_next      : std::ptr::null(),
            flags       : vk::FenceCreateFlags::SIGNALED
        };

        match VK_CHECK_UNSAFE!(self.vk_device.create_fence(&fence_ci, None)) {
            Some(inner_value)   => inner_value,
            None                => VK_LOGP!("Failed to create_fence")
        }
    }

    pub fn device_wait_idle(&self) {
        VK_CHECK_UNSAFE!(self.vk_device.device_wait_idle());
    }
}